package com.xca.touchdemo.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

public class TouchView extends AppCompatTextView {
    public static final String TAG = "View" ;

    public TouchView(@NonNull Context context) {
        super(context);
    }
    public TouchView(Context context , @Nullable AttributeSet attrs) {
        super(context , attrs);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent event){
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                //Toast.makeText(getContext(), "onTouchEvent_Down", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~~Down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~Move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~Up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~cancel");
                break;
        }
        return super.onTouchEvent(event) ;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event){
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "dispatchTouchEvent: ===============down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "dispatchTouchEvent: ================move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "dispatchTouchEvent: ================up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "dispatchTouchEvent: ===============cancel");
                break;
        }
        return super.dispatchTouchEvent(event);
    }
}
